{% extends "base.html" %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>仓库管理</h2>
        <a href="{{ url_for('storage.warehouse_add') }}" class="btn btn-primary">
            <i class="fas fa-plus"></i> 添加仓库
        </a>
    </div>

    <!-- 搜索表单 -->
    <div class="card mb-4">
        <div class="card-body">
            <form method="get" class="row g-3">
                <div class="col-md-4">
                    <label class="form-label">仓库名称</label>
                    <input type="text" class="form-control" name="name" value="{{ name }}">
                </div>
                <div class="col-md-4">
                    <label class="form-label">位置</label>
                    <input type="text" class="form-control" name="location" value="{{ location }}">
                </div>
                <div class="col-md-2">
                    <label class="form-label">状态</label>
                    <select class="form-select" name="status">
                        <option value="">所有状态</option>
                        <option value="normal" {% if status == 'normal' %}selected{% endif %}>正常</option>
                        <option value="maintenance" {% if status == 'maintenance' %}selected{% endif %}>维护中</option>
                        <option value="full" {% if status == 'full' %}selected{% endif %}>已满</option>
                    </select>
                </div>
                <div class="col-md-2">
                    <label class="form-label">&nbsp;</label>
                    <div class="d-grid">
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-search"></i> 搜索
                        </button>
                    </div>
                </div>
            </form>
        </div>
    </div>

    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>仓库名称</th>
                            <th>位置</th>
                            <th>容量(m³)</th>
                            <th>温度(°C)</th>
                            <th>湿度(%)</th>
                            <th>状态</th>
                            <th>备注</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for warehouse in warehouses %}
                        <tr>
                            <td>{{ warehouse.name }}</td>
                            <td>{{ warehouse.location }}</td>
                            <td>{{ warehouse.capacity }}</td>
                            <td>{{ warehouse.temperature }}</td>
                            <td>{{ warehouse.humidity }}</td>
                            <td>
                                {% if warehouse.status == 'normal' %}
                                    <span class="badge bg-success">正常</span>
                                {% elif warehouse.status == 'maintenance' %}
                                    <span class="badge bg-warning">维护中</span>
                                {% elif warehouse.status == 'full' %}
                                    <span class="badge bg-danger">已满</span>
                                {% endif %}
                            </td>
                            <td>{{ warehouse.notes }}</td>
                            <td>
                                <a href="{{ url_for('storage.warehouse_edit', id=warehouse.id) }}" class="btn btn-sm btn-info">
                                    <i class="fas fa-edit"></i> 编辑
                                </a>
                                <a href="{{ url_for('storage.warehouse_delete', id=warehouse.id) }}" 
                                   class="btn btn-sm btn-danger"
                                   onclick="return confirm('确定要删除该仓库吗？')">
                                    <i class="fas fa-trash"></i> 删除
                                </a>
                            </td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>

            <!-- 分页 -->
            {% if pagination and pagination.pages > 1 %}
            <nav aria-label="Page navigation" class="mt-4">
                <ul class="pagination justify-content-center">
                    <li class="page-item {% if not pagination.has_prev %}disabled{% endif %}">
                        <a class="page-link" href="{{ url_for('storage.warehouse_list', page=pagination.prev_num, name=name, location=location, status=status) if pagination.has_prev else '#' }}">
                            <i class="fas fa-chevron-left"></i>
                        </a>
                    </li>
                    {% for page in pagination.iter_pages(left_edge=2, left_current=2, right_current=3, right_edge=2) %}
                        {% if page %}
                            <li class="page-item {% if page == pagination.page %}active{% endif %}">
                                <a class="page-link" href="{{ url_for('storage.warehouse_list', page=page, name=name, location=location, status=status) }}">
                                    {{ page }}
                                </a>
                            </li>
                        {% else %}
                            <li class="page-item disabled">
                                <span class="page-link">...</span>
                            </li>
                        {% endif %}
                    {% endfor %}
                    <li class="page-item {% if not pagination.has_next %}disabled{% endif %}">
                        <a class="page-link" href="{{ url_for('storage.warehouse_list', page=pagination.next_num, name=name, location=location, status=status) if pagination.has_next else '#' }}">
                            <i class="fas fa-chevron-right"></i>
                        </a>
                    </li>
                </ul>
            </nav>
            <div class="text-center text-muted">
                共 {{ pagination.total }} 条记录，当前第 {{ pagination.page }}/{{ pagination.pages }} 页
            </div>
            {% endif %}
        </div>
    </div>
</div>
{% endblock %} 